<%@ page import="java.sql.*" %>
<%@include file="../connection.jsp" %>

<%
            try {
                HttpSession ses = request.getSession(true);
                String ses_username = ses.getValue("ses_uname").toString();

                out.println("<center>Hay, " + ses_username + "! " + "<a href=logout.jsp>Logout</a></center>");
            } catch (Exception e) {
                out.println("<center>Welcome, Guest! <a href=login.html>Login</a> or <a href=register.html>Register</a></center>");
            }
%>

<div id="banner"><p>&nbsp;</p></div>
<link href="css/style.css" rel="stylesheet" />

<nav>
    <ul>
        <li><a href="index.jsp">Home</a></li>
        <li><a href="#">Kalkulator</a>
            <ul>
                <li><a href="hitung-dana.jsp">Hitung Dana</a></li>
                <li><a href="rencanakan-dana.jsp">Rencanakan Dana</a></li>
                <li><a href="hitung-investasi.jsp">Hitung Investasi</a></li>
            </ul>
        </li>
        <li><a href="#">Investasi</a>
            <ul>
                <li><a href="reksadana.jsp">Reksadana</a></li>
                <li><a href="deposito.jsp">Deposito</a></li>
                <li><a href="emas.jsp">Emas</a></li>
                <li><a href="unitlink.jsp">Unitlink</a></li>
            </ul>
        </li>
        <li><a href="about.html">About</a></li>
        <li><a href="akunku.jsp">Akunku</a></li>
    </ul>
</nav>
<br><br>
<%
            try {
                HttpSession ses = request.getSession(true);
                String ses_user = ses.getValue("ses_uname").toString();

                if (ses_user != null) {
                    String sql = "SELECT * FROM t_user WHERE username = '" + ses_user + "'";
                    rs = stmt.executeQuery(sql);

                    if (rs.next()) {

                        String name = rs.getString(4);
                        String email = rs.getString(5);
                        String jeniskel = rs.getString(6);
%>
<form method="post" action="updateuser.jsp" name="myForm" onsubmit="return(validate());">
    <table width="" border="1" align="center" cellpadding="3" cellspacing="0">
        <tr>
            <td width="">Nama</td>
            <td width=""><input name="txtname" type="text" value="<% out.print(name);%>" />
                <input name="txtusername" type="hidden" value="<% out.print(ses_user);%>" /></td>
        </tr>
        <tr>
            <td>Email</td>
            <td><input name="txtemail" type="text" value="<% out.print(email);%>" /></td>
        </tr>
        <tr>
            <td>Jenis Kelamin</td>
            <td><input name="txtjeniskel" type="radio" <% if (jeniskel.equals("1")) {
                                        out.print("checked");
                                    }%> value="1"/> Laki
                <input name="txtjeniskel" type="radio" <% if (jeniskel.equals("2")) {
                                            out.print("checked");
                                        }%> value="2"/> Perempuan</td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><div align="right"><input type="submit" name="Submit" value="Simpan" /></div></td>
        </tr>
    </table>
</form>
<%
                    }
                }
            } catch (Exception e) {
                out.println("<center>Anda belum login</center>");
            }
%>
<%
            try {
                HttpSession ses = request.getSession(true);
                String ses_username = ses.getValue("ses_uname").toString();

                if (ses_username.equals("admin")) {
                    out.println("<br><center><a href=" + "./admin" + ">Manajemen User</a></center><br><center><a href=" + "./admin/info-investasi.jsp" + ">Info Investasi</a></center>");
                }
                {
                }
            } catch (Exception e) {
            }
%>
<script type="text/javascript">
    <!--
    // Form validation code will come here.
    function validate()
    {
 
        if( document.myForm.txtname.value == "" )
        {
            alert( "Nama belum diisi!" );
            document.myForm.txtname.focus() ;
            return false;
        }
        if( document.myForm.txtemail.value == "" )
        {
            alert( "Email belum diisi!" );
            document.myForm.txtemail.focus() ;
            return false;
        }
    }
</script>